package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.QuestionService;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    @Autowired
    private QuestionService questionService;

    @GetMapping("/todayBest")//今日佳人
    public ResponseEntity todayBest(){
         TodayBest vo= tanhuaService.todayBest();
         return ResponseEntity.ok(vo);
    }

    //推荐好友
    @GetMapping("/recommendation")
    public  ResponseEntity recommendation(RecommendUserDto dto){
          PageResult pageResult=tanhuaService.recommendation(dto);
          return ResponseEntity.ok(pageResult);
    }

    //查看佳人信息//顺便保存访客记录
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest best = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(best);
    }
    //查看陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
            String question=questionService.findByUserId(userId);
            return ResponseEntity.ok(question);
    }
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map){
        Integer obj =(Integer) map.get("userId");
        Long userId = Long.valueOf(obj);
        String reply = (String)map.get("reply");
        //发送消息
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/cards")//探花 返回list集合
    public ResponseEntity cards(){
       List<TodayBest> list= tanhuaService.queryCardsList();
       return ResponseEntity.ok(list);
    }

        @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId){
                tanhuaService.loveUser(likeUserId);
return ResponseEntity.ok(null);
        }
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId){
        tanhuaService.unLoveUser(likeUserId);
        return ResponseEntity.ok(null);
    }


    @GetMapping("/search")//搜附近
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,
                                                          @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = this.tanhuaService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }
}
